package com.scalar.chiptrack.finance.creditNote.forms;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.sales.LineItem;
import com.scalar.chiptrack.utils.AutoGrowingArrayList;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.commons.ClientInfo;

import java.util.ArrayList;

/**
 * User: Sujan
 * Date: Apr 13, 2007
 * Time: 2:48:14 PM
 */
public class CreditNoteForm extends ChipTrackActionForm
{
    private int customerId;
    private int salesOrderId;
    private String creditNoteNumber;
    private String issueDate;
    private String customerName;
    private String salesOrderNo;
    private String customerPONo;
    private String salesRep;
    private String endCustomerName;
    private String endUserName;
    private String payTerms;
    private String Comments;
    private ArrayList lineItems = new AutoGrowingArrayList(LineItem.class);
    private ArrayList cancelledLineItems = new ArrayList();
    private int creditNoteId;
    private ClientInfo clientInfo = null;
    private String noteType = null;
    private String status;
    private Address billingAddress;
    private Address shippingAddress;
    private double totalAdjustmentAmount;
    private String fromDate;
    private String toDate;
    private int customerShippingId;
    private String packingSlipLabel;
    private boolean isUnits;

    public int getCustomerId() {
        return customerId;
    }

    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }

    public int getSalesOrderId() {
        return salesOrderId;
    }

    public void setSalesOrderId(int salesOrderId) {
        this.salesOrderId = salesOrderId;
    }

    public String getCreditNoteNumber() {
        return creditNoteNumber;
    }

    public void setCreditNoteNumber(String creditNoteNumber) {
        this.creditNoteNumber = creditNoteNumber;
    }

    public String getIssueDate() {
        return issueDate;
    }

    public void setIssueDate(String issueDate) {
        this.issueDate = issueDate;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getSalesOrderNo() {
        return salesOrderNo;
    }

    public void setSalesOrderNo(String salesOrderNo) {
        this.salesOrderNo = salesOrderNo;
    }

    public String getCustomerPONo() {
        return customerPONo;
    }

    public void setCustomerPONo(String customerPONo) {
        this.customerPONo = customerPONo;
    }

    public String getSalesRep() {
        return salesRep;
    }

    public void setSalesRep(String salesRep) {
        this.salesRep = salesRep;
    }

    public String getEndCustomerName() {
        return endCustomerName;
    }

    public void setEndCustomerName(String endCustomerName) {
        this.endCustomerName = endCustomerName;
    }

    public String getEndUserName() {
        return endUserName;
    }

    public void setEndUserName(String endUserName) {
        this.endUserName = endUserName;
    }

    public String getPayTerms() {
        return payTerms;
    }

    public void setPayTerms(String payTerms) {
        this.payTerms = payTerms;
    }

    public ArrayList getLineItems() {
        return lineItems;
    }

    public void setLineItems(ArrayList lineItems) {
        this.lineItems = lineItems;
    }

    public int getCreditNoteId() {
        return creditNoteId;
    }

    public void setCreditNoteId(int creditNoteId) {
        this.creditNoteId = creditNoteId;
    }


    public String getComments() {
        return Comments;
    }

    public void setComments(String comments) {
        Comments = comments;
    }

    public ClientInfo getClientInfo() {
        return clientInfo;
    }

    public void setClientInfo(ClientInfo clientInfo) {
        this.clientInfo = clientInfo;
    }


    public String getNoteType() {
        return noteType;
    }

    public void setNoteType(String noteType) {
        this.noteType = noteType;
    }


    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }


    public ArrayList getCancelledLineItems() {
        return cancelledLineItems;
    }

    public void setCancelledLineItems(ArrayList cancelledLineItems) {
        this.cancelledLineItems = cancelledLineItems;
    }

    public Address getBillingAddress() {
        return billingAddress;
    }

    public void setBillingAddress(Address billingAddress) {
        this.billingAddress = billingAddress;
    }

    public Address getShippingAddress() {
        return shippingAddress;
    }

    public void setShippingAddress(Address shippingAddress) {
        this.shippingAddress = shippingAddress;
    }

    public String getBillingAddressAsHTML ()
    {
        return billingAddress.getAddressAsHTML();
    }

    public String getShippingAddressAsHTML()
    {
        return shippingAddress.getAddressAsHTML();
    }


    public double getTotalAdjustmentAmount()
    {
        return totalAdjustmentAmount;
    }

    public void setTotalAdjustmentAmount(double totalAdjustmentAmount)
    {
        this.totalAdjustmentAmount = totalAdjustmentAmount;
    }

    public String getClientAddrWithOutEmailObjFormatted()
	{
        Address add = clientInfo.getAddress();
        StringBuffer formatAddress = new StringBuffer();

        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );
        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );
        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );
        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );
        String formatState = CreditNoteForm.getFormatedCityState(add);
        if ( formatState.trim().length() !=0 )
           formatAddress.append ("<BR>"+formatState);
        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );

        return formatAddress.toString() ;
	}
    public static String getFormatedCityState( Address add )
	{
	    String addr = "";
        if( add.getCity() != null && add.getCity() .trim() .length() != 0 )
            addr = add.getCity() + ",&nbsp;" ;
        if (  add.getState() != null  &&  add.getState().trim().length() != 0 )
		    addr =  addr  + add.getState();
		if( add.getZipCode() != null &&  add.getZipCode().trim().length() != 0 )
		{
		     if ( addr.trim().length() !=0 )
		         addr = addr + "&nbsp;-&nbsp;" + add.getZipCode();
		    else
				 addr = addr + add.getZipCode();
		}
		if( add.getCountry() != null && add.getCountry().trim().length() != 0 )
	    {
	        if ( addr.trim().length() != 0 )
			    addr = addr + ",&nbsp;" + add.getCountry();
			else
			    addr = addr + add.getCountry();
	   	}
		return addr;
	}
    public String getTotalAdjustmentAmountAsString()
    {
        return StringUtils.formatAmount( totalAdjustmentAmount, "$###,###.###" );
    }

    public String getFromDate() {
        return fromDate;
    }

    public void setFromDate(String fromDate) {
        this.fromDate = fromDate;
    }

    public String getToDate() {
        return toDate;
    }

    public void setToDate(String toDate) {
        this.toDate = toDate;
    }

    public int getCustomerShippingId() {
        return customerShippingId;
    }

    public void setCustomerShippingId(int customerShippingId) {
        this.customerShippingId = customerShippingId;
    }

    public String getPackingSlipLabel() {
        return packingSlipLabel;
    }

    public void setPackingSlipLabel(String packingSlipLabel) {
        this.packingSlipLabel = packingSlipLabel;
    }

    public boolean getIsUnits() {
        return isUnits;
    }

    public void setIsUnits(boolean isUnits) {
        this.isUnits = isUnits;
    }
}
